﻿/*
 *	(*^。^*) TFrameWork License (*^。^*)
 */

/*
 *  Title :
 *
 *  Description :
 *
 *
 *  Date :
 *
 *  Author : DengPing
 *
 *  Modify :
 */

using UnityEditor.UIElements;
using UnityEngine.UIElements;

namespace TFrameWork.Module.ActionEditor
{
    public abstract class EventBaseInspector
    {
        protected VisualElement root;
        protected TrackItemStyleBase itemStyle;
        protected TrackEventBase data;

        public virtual void Show(VisualElement root)
        {
            this.root = root;
            itemStyle = ActionEditorInspector.currentTrackItemStyle;
            data = itemStyle.eventData;

            // 轨道长度
            ShowTrackName();
            ShowStartIndex();
            ShowDurationIndex();
        }

        protected void ShowTrackName()
        {
            TextField nameField = new TextField("轨道名称");
            nameField.value = data.trackName;
            nameField.RegisterCallback<FocusOutEvent>(p =>
            {
                if (data.trackName != nameField.value)
                {
                    data.trackName = nameField.value;
                    itemStyle.ResetView();
                }
            });
            root.Add(nameField);
        }

        protected void ShowStartIndex()
        {
            IntegerField startIndexField = new IntegerField("起始帧");
            startIndexField.value = data.startIndex;
            startIndexField.RegisterCallback<FocusOutEvent>(p =>
            {
                if (data.startIndex != startIndexField.value)
                {
                    data.startIndex = startIndexField.value;
                    itemStyle.ResetView();
                }
            });
            root.Add(startIndexField);
        }

        protected void ShowDurationIndex()
        {
            IntegerField durationIndexField = new IntegerField("持续帧");
            durationIndexField.value = data.durationIndex;
            durationIndexField.RegisterCallback<FocusOutEvent>(p =>
            {
                if (data.durationIndex != durationIndexField.value)
                {
                    data.durationIndex = durationIndexField.value;
                    itemStyle.ResetView();
                }
            });
            root.Add(durationIndexField);
        }
    }
}
